package com.app.ui.adapter.base;

import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

/**
 * 子类继承它
 * Created by guom on 2016/11/20.
 */

public abstract class BaseRecyclerDataAdapter<T, VH extends RecyclerView.ViewHolder> extends BaseRecyclerViewAdapter<VH> {
    protected List<T> list = new ArrayList<>();

    public void setData(List<T> list) {
        if (list == null) {
            return;
        }
        this.list = list;
        notifyDataSetChanged();
    }

    public void addData(List<T> list) {
        if (list == null) {
            return;
        }
        this.list.addAll(list);
        notifyDataSetChanged();
    }

    public void addData(int index, List<T> list) {
        if (list == null) {
            return;
        }
        this.list.addAll(index, list);
        notifyDataSetChanged();
    }

    public void addData(T data) {
        if (data == null) {
            return;
        }
        list.add(data);
        notifyDataSetChanged();
    }

    public void addData(int index, T data) {
        if (data == null) {
            return;
        }
        list.add(index, data);
        notifyDataSetChanged();
    }

    public void setData(int index, T data) {
        if (data == null) {
            return;
        }
        list.set(index, data);
        notifyDataSetChanged();
    }

    //-------------------------------------
    @Override
    public int getChildCount() {
        return list.size();
    }
}
